home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
news
/
readers
/
skim-0.8
/
skim-0
/
skim-0.8.4
/
ArticleTest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-18
|
7KB
|
276 lines
/*
* NAME
* ArticleTest.c
* DESCRIPTION
* Test the Article ADT. Run this test by typing 'make test' in the source
* directory of skim.
* COPYRIGHT
* Copyright (C) 1996 Rene W.J. Pijlman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* VERSION
* $Header: /home/rene/sys/CVS_MasterSourceRepository/skim/ArticleTest.c,v 1.7 1996/02/18 11:40:16 rene Exp $
* Distributed with Skim version 0.8.4.
*/
#include "Article.h"
#include "StandardIO.h"
#include "MemAlloc.h"
#include <assert.h>
#include <string.h>
/* assert()'s must be in effect in this file. */
#ifdef NDEBUG
# undef NDEBUG
#endif
static void TestCreation( Article * Article1 )
{
ArticleDestroy( ArticleCreate() );
*Article1 = ArticleCreate();
}
static void TestMinimalNewArticle(void)
{
VarBuf Newsgroups = VBCreateString("test");
VarBuf Subject = VBCreateString("test, please ignore");
VarBuf From = VBCreateString("me");
VarBuf NewVB = NULL;
VarBuf Date = VBCreateString("today");
Article New = ArticleConstructNew( Newsgroups, Subject, From, NULL,
NULL, NULL, NULL, NULL );
ArticleSetHeaderLine( New, HL_DATE, Date );
NewVB = ArticleGetVB( New );
if ( strcmp( VBAsString(NewVB),
"From: me\n"
"Date: today\n"
"Lines: 2\n"
"Newsgroups: test\n"
"Subject: test, please ignore\n"
"\n"
DEFAULT_BODY_FOR_NEW_ARTICLE ))
{
SIOPrintf( StandardError,
"Minimal new article is not correct:\n%V",
NewVB );
exit( EXIT_FAILURE );
}
VBDestroy( Newsgroups );
VBDestroy( Subject );
VBDestroy( From );
VBDestroy( NewVB );
VBDestroy( Date );
ArticleDestroy( New );
}
static void TestConstruction( Article Article1 )
{
VarBuf BufA = VBCreate();
VarBuf BufB = VBCreate();
VarBuf BufC = VBCreate();
VarBuf BufD = VBCreate();
VarBuf BufE = VBCreate();
VarBuf BufF = VBCreate();
VarBuf ArticleVB = NULL;
VBPrintf( BufA, "A" );
VBPrintf( BufB, "B" );
VBPrintf( BufC, "C" );
VBPrintf( BufD, "D\n\n\n\n\n" );
VBPrintf( BufE, "E" );
VBPrintf( BufF, "F" );
ArticleSetHeaderLine( Article1, HL_SUBJECT, BufA );
ArticleSetHeaderLine( Article1, HL_FROM, BufB );
ArticleSetHeaderLine( Article1, HL_DATE, BufE );
ArticleSetHeaderLine( Article1, HL_LINES, BufF );
/* Test overwrite of headerline. */
ArticleSetHeaderLine( Article1, HL_NEWSGROUPS, BufA );
ArticleSetHeaderLine( Article1, HL_NEWSGROUPS, BufC );
ArticleSetBody( Article1, BufD );
if ( !ArticleIsOK( Article1 ) )
{
SIOPrintf( StandardError, "%V",
ArticleGetErrorMessages(Article1) );
exit( EXIT_FAILURE );
}
ArticleVB = ArticleGetVB( Article1 );
if ( strcmp( VBAsString(ArticleVB),
"Subject: A\nFrom: B\nDate: E\nLines: 1\nNewsgroups: C\n\nD\n" ) )
{
SIOPrintf( StandardError,
"Constructed article is incorrect:\n%s",
VBAsString( ArticleVB ) );
exit( EXIT_FAILURE );
}
VBDestroy( BufA );
VBDestroy( BufB );
VBDestroy( BufC );
VBDestroy( BufD );
VBDestroy( BufE );
VBDestroy( BufF );
VBDestroy( ArticleVB );
}
static void TestReply( Article Article1 )
{
Article Reply = NULL;
VarBuf ReplyVB = NULL;
VarBuf Date = VBCreateString("the current date");
VarBuf From = VBCreateString("Myself");
VarBuf Path = VBCreateString("From here to there");
VarBuf ReplyTo = VBCreateString("Me");
VarBuf Organization = VBCreateString("No way");
VarBuf Signature = VBCreateString(":-)");
VarBuf X_NewsReader = VBCreateString("skim");
assert( ArticleIsOK( Article1 ) );
Reply = ArticleConstructReply( Article1, From, Path, ReplyTo,
Organization, Signature,
X_NewsReader );
ArticleSetHeaderLine( Reply, HL_DATE, Date );
assert( ArticleIsOK( Reply ) );
ReplyVB = ArticleGetVB( Reply );
assert( ReplyVB != NULL );
if ( strcmp( VBAsString(ReplyVB),
"From: Myself\n"
"Path: From here to there\n"
"Reply-To: Me\n"
"Organization: No way\n"
"X-Newsreader: skim\n"
"Date: the current date\n"
"Lines: 5\n"
"Newsgroups: C\n"
"Subject: Re: A\n"
"\n"
"B wrote:\n"
">D\n"
"\n"
"-- \n"
":-)\n"
) )
{
SIOPrintf( StandardError, "Reply is incorrect:\n%V", ReplyVB );
exit( EXIT_FAILURE );
}
ArticleDestroy( Reply );
VBDestroy( ReplyVB );
VBDestroy( From );
VBDestroy( Path );
VBDestroy( ReplyTo );
VBDestroy( Organization );
VBDestroy( Signature );
VBDestroy( X_NewsReader );
VBDestroy( Date );
}
static void TestConstructNew( void )
{
Article NewArticle = NULL;
VarBuf NewsGroups = VBCreateString("alt.test");
VarBuf Subject = VBCreateString("test, please ignore");
VarBuf From = VBCreateString("Myself");
VarBuf Date = VBCreateString("the current date");
VarBuf Path = VBCreateString("From here to there");
VarBuf ReplyTo = VBCreateString("Me");
VarBuf Organization = VBCreateString("No way");
VarBuf Signature = VBCreateString(":-)");
VarBuf X_NewsReader = VBCreateString("skim");
VarBuf NewArticleVB = NULL;
NewArticle = ArticleConstructNew(
NewsGroups, Subject, From, Path, ReplyTo,
Organization, Signature, X_NewsReader );
ArticleSetHeaderLine( NewArticle, HL_DATE, Date );
NewArticleVB = ArticleGetVB( NewArticle );
if ( strcmp( VBAsString(NewArticleVB),
"From: Myself\n"
"Path: From here to there\n"
"Reply-To: Me\n"
"Organization: No way\n"
"X-Newsreader: skim\n"
"Date: the current date\n"
"Lines: 5\n"
"Newsgroups: alt.test\n"
"Subject: test, please ignore\n"
"\n"
DEFAULT_BODY_FOR_NEW_ARTICLE
"\n-- \n"
":-)\n"
) )
{
SIOPrintf( StandardError,
"New article is incorrect:\n%V", NewArticleVB );
exit( EXIT_FAILURE );
}
ArticleDestroy( NewArticle );
VBDestroy( From );
VBDestroy( Path );
VBDestroy( ReplyTo );
VBDestroy( Date );
VBDestroy( Organization );
VBDestroy( Signature );
VBDestroy( X_NewsReader );
VBDestroy( NewArticleVB );
VBDestroy( Subject );
VBDestroy( NewsGroups );
}
int main( void )
{
Article Article1;
TestCreation( &Article1 );
TestMinimalNewArticle();
TestConstruction( Article1 );
TestConstructNew();
TestReply( Article1 );
ArticleDestroy( Article1 );
SIOPrintf( StandardOutput, "OK\n" );
return EXIT_SUCCESS;
}